package com.hex.liyue.usermodule.view;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.hex.liyue.R;
import com.hex.liyue.commonmodule.utils.L;
import com.hex.liyue.commonmodule.utils.ScreenUtils;

/**
 * 这是一个性别筛选的弹框
 * Created by WJ on 2016/6/13.
 */
public class PopStarSign extends PopupWindow implements View.OnClickListener {
    private final Context context;
    private TextView tv_start1,tv_start2,tv_start3,tv_start4,tv_start5,tv_start6,tv_start7,tv_start8,tv_start9,tv_start10,tv_start11,tv_start12, tv_sift_cancel;
    private OnBtnClickListener onBtnClickListener;

    public interface OnBtnClickListener {

        void onBtnStart1ClickListener();
        void onBtnStart2ClickListener();
        void onBtnStart3ClickListener();
        void onBtnStart4ClickListener();
        void onBtnStart5ClickListener();
        void onBtnStart6ClickListener();
        void onBtnStart7ClickListener();
        void onBtnStart8ClickListener();
        void onBtnStart9ClickListener();
        void onBtnStart10ClickListener();
        void onBtnStart11ClickListener();
        void onBtnStart12ClickListener();
    }

    public void setOnBtnClickListener(OnBtnClickListener onBtnClickListener) {
        this.onBtnClickListener = onBtnClickListener;
    }

    public PopStarSign(Context context) {
        this.context = context;
        View view = View.inflate(context, R.layout.pop_star_sign, null);
        setWidth(ScreenUtils.getScreenWidth(context));
        setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        setContentView(view);
        setFocusable(true);//设置获取焦点
        setTouchable(true);//设置可以触摸
        setOutsideTouchable(true);//设置外边可以点击
        setBackgroundDrawable(new BitmapDrawable());
        //设置点击事件的监听
        setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                    //不在该界面的点击事件
                    dismiss();
                    return true;
                }
                return false;
            }
        });


        initView(view);
        initListener();
    }

    private void initView(View view) {
        tv_start1 = (TextView) view.findViewById(R.id.tv_start1);
        tv_start2 = (TextView) view.findViewById(R.id.tv_start2);
        tv_start3 = (TextView) view.findViewById(R.id.tv_start3);
        tv_start4 = (TextView) view.findViewById(R.id.tv_start4);
        tv_start5 = (TextView) view.findViewById(R.id.tv_start5);
        tv_start6 = (TextView) view.findViewById(R.id.tv_start6);
        tv_start7 = (TextView) view.findViewById(R.id.tv_start7);
        tv_start8 = (TextView) view.findViewById(R.id.tv_start8);
        tv_start9 = (TextView) view.findViewById(R.id.tv_start9);
        tv_start10 = (TextView) view.findViewById(R.id.tv_start10);
        tv_start11 = (TextView) view.findViewById(R.id.tv_start11);
        tv_start12 = (TextView) view.findViewById(R.id.tv_start12);
        tv_sift_cancel = (TextView) view.findViewById(R.id.tv_sift_cancel);
    }

    private void initListener() {
        tv_start1.setOnClickListener(this);
        tv_start2.setOnClickListener(this);
        tv_start3.setOnClickListener(this);
        tv_start4.setOnClickListener(this);
        tv_start5.setOnClickListener(this);
        tv_start6.setOnClickListener(this);
        tv_start7.setOnClickListener(this);
        tv_start8.setOnClickListener(this);
        tv_start9.setOnClickListener(this);
        tv_start10.setOnClickListener(this);
        tv_start11.setOnClickListener(this);
        tv_start12.setOnClickListener(this);
        tv_sift_cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_start1:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart1ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start2:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart2ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start3:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart3ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start4:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart4ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start5:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart5ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start6:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart6ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start7:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart7ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start8:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart8ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start9:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart9ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start10:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart10ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start11:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart11ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_start12:
                if (onBtnClickListener != null) {
                    onBtnClickListener.onBtnStart12ClickListener();
                }
                dismiss();
                break;
            case R.id.tv_sift_cancel:
                L.d("WJ", "点击了取消");
                dismiss();
                break;

        }
    }
}
